package com.palnar.ilecker.model;

import java.io.Serializable;

import org.ksoap2.serialization.SoapObject;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;

import com.palnar.ilecker.utils.XmlDocumentUtility;

public class ServiceStation extends ItemBase implements Serializable {
	private Integer clientId = 0;
	private Integer serverId = 0;
	private String name = "";
	private ServiceStationType type;
	private Integer serviceEndPointId = 0;

	private static String idArg = "Id";
	private static String nameArg = "Name";
	private static String typeArg = "Type";
	private static String serviceEndPointIdArg = "ServiceEndPointId";

	public ServiceStation() {
		this.type = new ServiceStationType();
	}

	public Integer getClientId() 
	{
		return this.clientId;
	}
	
	public Integer getServerId() 
	{
		return this.serverId;
	}

//	public String getName()
//	{
//		return this.name;
//	}

	public Integer getServiceEndPointId() 
	{
		return this.serviceEndPointId;
	}
	
	public ServiceStationType getServiceStationType() 
	{
		return this.type;
	}
	
	public void setClientId(Integer serviceStationId) 
	{
		this.clientId = serviceStationId;
	}
	
	public void setServerId(Integer serviceStationId) 
	{
		this.serverId = serviceStationId;
	}

//	public void setName(String serviceStationName)
//	{
//		this.name = serviceStationName;
//	}

	public void setServiceEndPointId(Integer serviceStationEndPointId) 
	{
		this.serviceEndPointId = serviceStationEndPointId;
	}

	public void setServiceStationType(ServiceStationType type) 
	{
		this.type = type;
	}

	public void getSerializationData(Element parentElement, Document document) {

		Element idElement = document.createElement(idArg);
		Node idNode = document.createTextNode("id");
		idNode.setNodeValue(serverId.toString());
		idElement.appendChild(idNode);
		parentElement.appendChild(idElement);

		Element nameElement = document.createElement(nameArg);
		Node nameNode = document.createTextNode("name");
		nameNode.setNodeValue(getName().toString());
		nameElement.appendChild(nameNode);
		parentElement.appendChild(nameElement);

		Element typeElement = document.createElement(typeArg);
		this.type.getSerializationData(typeElement, document);
		parentElement.appendChild(typeElement);

		Element serviceEndPointElement = document
				.createElement(serviceEndPointIdArg);
		Node serviceEndPointNode = document.createTextNode("serviceEndPointId");
		serviceEndPointNode.setNodeValue(serviceEndPointId.toString());
		serviceEndPointElement.appendChild(serviceEndPointNode);
		parentElement.appendChild(serviceEndPointElement);

	}

	public static ServiceStation ServiceStationTypeBuilder(SoapObject object) {

		ServiceStation serviceStation = new ServiceStation();

		Object ServiceStationIdObj = object.getProperty("ServiceStationId");

		if (!ServiceStationIdObj.toString().equals(XmlDocumentUtility.nullString)) {
			serviceStation.setServerId(Integer.parseInt(ServiceStationIdObj
					.toString()));
		}

		Object ServiceStationNameObj = object.getProperty("ServiceStationName");

		if (!ServiceStationNameObj.toString().equals(XmlDocumentUtility.nullString)) {
			serviceStation.setName(Integer.parseInt(ServiceStationNameObj.toString()));
		}

		Object ServiceEndPointIdObj=object
				.getProperty("ServiceEndPointId");
		
		if (!ServiceEndPointIdObj.toString().equals(XmlDocumentUtility.nullString)) {
			serviceStation.setServiceEndPointId(Integer.parseInt(ServiceEndPointIdObj.toString()));
		}
	
		SoapObject serviceStationType = (SoapObject) object.getProperty("ServiceStationType");
		if(serviceStationType != null)
		{
			if (!serviceStationType.toString().equals(XmlDocumentUtility.nullString))
			{
			serviceStation.setServiceStationType(ServiceStationType
				.ServiceStationTypeBuilder(serviceStationType));
			}
		
		}

		return serviceStation;
	}
}
